package cn.edu.neu.vmmigeval.evaluation;


import cn.edu.neu.vmmigeval.cloud.config.Migration;
import cn.edu.neu.vmmigeval.cloud.entity.Vm;

import java.util.List;

public class VmMigrationCost {
	//打印每个周期的迁移花费
	public double getMigrationCost(List<Migration> migrations, int size) {//throws Exception
		double totalCost =0.0;
		if(migrations!=null&&migrations.size()!=0){
			for (Migration migration : migrations) {
				List<Vm> vms = migration.getVms();
				if(vms!=null&&vms.size()!=0){
					for (Vm vm : vms) {
						double cpu = (double)vm.getCurrentCpu()/vm.getTotalCpu();
						double time = (double)vm.getCurrentRam()/(vm.getHost().getTotalBw()-vm.getHost().getCurrentBw());
						double capacity = cpu*time;
						totalCost+=capacity;
					}
				}
			}
		}
		return totalCost;
	}
	/*public static void main(String[] args) {
		
		int a =1,b =2;
		double c = (double)(a/b);
		System.out.println(c);
		
	}*/
}
